package com.wish.wishauth.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.wishauth.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import vo.ResultEntity;

import java.security.Principal;
import java.util.List;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author zhaiwj
 * @since 2021-03-28
 */
@RestController
@RequestMapping("/admin")
@Slf4j
public class SysUserController {
    @Autowired
    ConsumerTokenServices consumerTokenServices;

    @RequestMapping("/token/logout")
    public ResultEntity logout(String access_token) {
        if (consumerTokenServices.revokeToken(access_token)) {
            return ResultEntity.ok("注销成功");
        } else {
            return ResultEntity.ok("注销失败");
        }

    }

    @GetMapping("/user/info")
    public Principal user(Principal member) {
        log.info("====" + member + "@@@@");
        return member;
    }

    @Autowired
    ISysUserService iSysUserService;

    @RequestMapping("/test")
    public String test() {
        Wrapper wrapper = new QueryWrapper<>();
        List list = iSysUserService.list(wrapper);
        log.info("list:{}", JSON.toJSONString(list));
        return "成功";
    }



}

